<template>
  <div>
    <span>查看班级评定情况：</span>
    <el-select
      v-model="scholarship"
      placeholder="请选择奖学金类型"
      class="class_select"
      clearable
    >
      <el-option
        v-for="item in scholarshiplist"
        :key="item.id"
        :label="item.name"
        :value="item.id"
      >
      </el-option>
    </el-select>
    <el-select
      v-model="student_class"
      placeholder="请选择班级"
      class="class_select"
      clearable
    >
      <el-option
        v-for="item in class_list"
        :key="item.id"
        :label="item.classname"
        :value="item.id"
      >
      </el-option>
    </el-select>
    <el-select
      v-model="semester"
      placeholder="请选择学期"
      class="class_select"
      clearable
    >
      <el-option
        v-for="item in semesterlist"
        :key="item.value"
        :label="item.name"
        :value="item.value"
      >
      </el-option>
    </el-select>
    <el-button type="primary" @click="get_student_records">查看</el-button>
    <!-- 综合成绩表 -->
    <el-table :data="records" border style="width: 100%">
      <el-table-column prop="user_id.name" label="姓名"> </el-table-column>
      <el-table-column prop="course_results" label="学期成绩">
      </el-table-column>
      <el-table-column prop="character_result" sortable label="品德成绩">
      </el-table-column>
      <el-table-column prop="study_result" sortable label="学业成绩">
      </el-table-column>
      <el-table-column prop="style_result" sortable label="文体成绩">
      </el-table-column>
      <el-table-column prop="total_score" sortable label="总成绩">
      </el-table-column>
      <el-table-column prop="rank" sortable label="排名" type="index">
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { mapState } from "vuex";
import { request } from "../request/http";
export default {
  name: "class_evaluation",
  data() {
    return {
      instructor_id: "",
      instructor_name: "",
      student_class: "",
      class_list: [],
      records: [],
      scholarship: "",
      scholarshiplist: [],
      semester: "",
      semesterlist: [
        {
          name: "大一上期",
          value: "1",
        },
        {
          name: "大一下期",
          value: "2",
        },
        {
          name: "大二上期",
          value: "3",
        },
        {
          name: "大二下期",
          value: "4",
        },
        {
          name: "大三上期",
          value: "5",
        },
        {
          name: "大三下期",
          value: "6",
        },
        {
          name: "大四上期",
          value: "7",
        },
        {
          name: "大四下期",
          value: "8",
        },
      ],
    };
  },
  computed: {
    ...mapState({
      username: (state) => state.name,
      roleid: (state) => state.role,
      userid: (state) => state.user_id,
      userinfo: (state) => state.userinfo,
    }),
  },
  methods: {
    getUserInfo() {
      this.name = this.username;
      this.instructor_id = this.userinfo.instructor_id.id;
      this.instructor_name = this.userinfo.instructor_id.instructor;
    },
    get_student_records() {
      if (!this.scholarship) {
        this.$message.error("请先选择奖学金类型");
        return
      }
      if (!this.semester) {
        this.$message.error("请先选择学期");
        return
      }
      if (this.student_class) {
        request({
          url: "/score-rule/get-all-student-records/",
          params: {
            class_id: this.student_class,
            scholarship_id: this.scholarship,
            semester: this.semester
          },
        })
          .then((res) => {
            this.records = res.data;
          })
          .catch((err) => {});
      } else {
        this.$message.error("请先选择班级");
      }
    },
    get_all_scholarship() {
      request({
        url: "/score-rule/get-all-scholarship/",
      })
        .then((res) => {
          this.scholarshiplist = res.data;
        })
        .catch((err) => {
          this.$message.error("请求出错");
        });
    },
  },
  created() {
    this.getUserInfo();
    this.get_all_scholarship();
    if (this.instructor_id) {
      request({
        url: "/score-rule/get-instructor-class/",
        params: {
          instructor_id: this.instructor_id,
        },
      })
        .then((res) => {
          this.class_list = res.data;
        })
        .catch((err) => {});
    }
  },
};
</script>
<style>
.class_select {
  margin: 10px 0;
}
</style>
